<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>高校宿舍管理系统-假期留校管理</title>
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="../../layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layui/css/public.css" media="all">
    <link rel="stylesheet" href="../../layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style type="text/css">
        .layui-table-cell {
            text-align: center;
            height: auto;
            white-space: normal;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <!-- 表格头部工具栏 -->
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button id="exportExcel" class="layui-btn layui-btn-sm data-add-btn" lay-event="export">
                    <i class="layui-icon layui-icon-file"></i>导出
                </button>
            </div>
        </script>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-sm" lay-event="agree">
                <i class="layui-icon layui-icon-ok"></i>批准</a>
            <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="disagree">
                <i class="layui-icon layui-icon-close"></i>不批准</a>
        </script>

        <script type="text/html" id="opinionImg">
            <img src="{{d.opinion}}" alt="家长意见" style="width: 100px;height: 100px"/>
        </script>

        <div style="display: none;padding: 5px" id="approveWindow">
            <form class="layui-form layuimini-form" id="dataFrm" lay-filter="dataFrm">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 80px !important;">教师意见</label>
                    <div class="layui-input-block" style="width: 250px;margin-left: 120px !important;">
                        <input type="hidden" name="id" id="id">
                        <input type="hidden" name="approvetype" id="approvetype">
                        <textarea name="approvetext" id="approvetext" autocomplete="off"
                                  class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="text-align: center;margin-right: 150px;margin-top: 20px;">
                        <button class="layui-btn" id="submitBtn" type="button" lay-submit lay-filter="doSubmit">
                            <span class="layui-icon">提交</span>
                        </button>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-row layui-col-space15">
            <div class="layui-col-xs12 layui-col-md9" style="text-align: center;margin-top: 50px;">
                <div id="echarts-pies" style="background-color:#ffffff;min-height:400px;padding: 10px"></div>
            </div>
        </div>
    </div>
</div>
<script src="../layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../layui/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'layer', 'echarts'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            table = layui.table,
            echarts = layui.echarts;

        var tableIns = table.render({
            elem: '#currentTableId',
            url: '/teacher/stayin/list',
            toolbar: '#toolbarDemo',
            cols: [
                [
                    {field: 'id', title: 'ID', hide: true},
                    {field: 'stuid', width: 130, title: '学号'},
                    {field: 'stuname', width: 100, title: '姓名'},
                    {field: 'reason', minWidth: 200, title: '留校原因'},
                    {field: 'time', width: 120, title: '留校截止时间'},
                    {field: 'opinion', width: 250, title: '家长意见', align: "center", templet: "#opinionImg"},
                    {field: 'stucollege', width: 110, title: '学院'},
                    {field: 'studept', width: 110, title: '专业'},
                    {field: 'stuclass', width: 100, title: '班级'},
                    {field: 'brcode', width: 110, title: '宿舍'},
                    {field: 'stutel', width: 130, title: '联系方式'},
                    {field: 'stututortel', width: 130, title: '家长联系方式'},
                    {field: 'approvetext', minWidth: 150, title: '教师意见'},
                    {field: 'approveValue', width: 100, title: '审核结果', align: "center"},
                    {
                        title: '操作',
                        width: 190,
                        toolbar: '#currentTableBar',
                        align: "center",
                        fixed: "right",
                        style: "height:110px"
                    }
                ]
            ],
            limits: [5, 10, 20],
            limit: 5,
            page: true,
            skin: 'line',
            even: true,
            done: function (res, curr, count) {
                // 鼠标移动到图片上时放大显示
                hoverOpenImg();
            }
        });

        $(function () {
            getPieData();
        });

        /**
         * 获取饼状图的数据
         */
        function getPieData() {
            $.ajax({
                type: "get",
                url: "/teacher/stayin/echartsData",
                async: true,
                dataType: "json",
                success: function (result) {
                    console.log(result);
                    var echartsPies = echarts.init(document.getElementById('echarts-pies'), 'walden');
                    var optionPies = {
                        title: {
                            text: '留校学生宿舍分布图',
                            x: 'center'
                        },
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'right',
                            data: result.data
                        },
                        series: [
                            {
                                name: '宿舍区',
                                type: 'pie',
                                radius: '60%',
                                center: ['50%', '50%'],
                                roseType: 'radius',
                                data: result.series,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    echartsPies.setOption(optionPies, true);
                },
                error: function () {
                    layer.msg("网络错误！", {icon: 1});
                }
            });
        }

        function hoverOpenImg() {
            var imgShow = null; // tips提示
            $('td img').hover(function () {
                var img = "<img src='" + $(this).attr('src') + "' style='width:100%;height: 100%' />";
                imgShow = layer.tips(img, this, {
                    tips: [2, 'rgba(41,41,41,.5)'],
                    area: ["350px", "350px"]
                });
            }, function () {
                layer.close(imgShow);
            });
        }

        var windowIndex;

        // 监听行工具栏事件
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case "agree":
                    data['approvetype'] = 1;
                    break;
                case "disagree":
                    data['approvetype'] = 0;
                    break;
            }
            openApproveWindow(data);
        });

        //表格头部工具栏触发事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === "export") {
                window.location.href = "/teacher/stayin/export.action";
            }
            ;
        });

        // 打开审核意见窗口
        function openApproveWindow(data) {
            windowIndex = layer.open({
                type: 1,
                title: "审批学生留校申请",
                area: ["450px", "240px"],
                content: $("#approveWindow"),
                success: function () {
                    form.val("dataFrm", data);
                }
            });
        }

        //监听表单提交事件
        form.on("submit(doSubmit)", function (data) {
            console.log(data);
            layer.confirm("确定提交吗？", {icon: 3, title: '提示'}, function (index) {
                var url = "/teacher/stayin/approve";
                $.post(url, data.field, function (result) {
                    if (result.success) {
                        tableIns.reload();
                        layer.close(windowIndex);
                        layer.msg(result.msg, {icon: 1});
                    } else {
                        layer.msg(result.msg, {icon: 2});
                    }
                }, "json");
                layer.close(index);
            });
            return false;
        });
    });
</script>
</body>
</html>